#ifndef __CHAT_LOG_OP__H__ 
#define __CHAT_LOG_OP__H__

#include <interface/data_op/chat_log.h>

namespace aot{ namespace data{
    
class chat_log_info_impl : public ichat_log_info
{
public:
    virtual ~chat_log_info_impl (){;}
    chat_log_info_impl()
    {
        id = 0;
        chat_type = 0;
        sign_status = 0;
		is_show = 0;

        session_id = &session_id_impl;
        user_id = &user_id_impl; 
        user_nickname = &user_nickname_impl;
        message = &message_impl;
		message_remove_tag = &message_remove_tag_impl;
        msg_datetime = &msg_datetime_impl;   
    }
public:
    virtual  bool clone(ichat_log_info** out) 
    {
        chat_log_info_impl* p = new chat_log_info_impl();
        *out = p;
        return p->assign(this);
    }
    virtual  bool assign(const ichat_log_info* in) 
    {
        if (NULL==in)
            return false;

        chat_log_info_impl* p = (chat_log_info_impl*) in;
        *this = *p;

        session_id = &session_id_impl;
        user_id = &user_id_impl; 
        user_nickname = &user_nickname_impl;
        message = &message_impl;
		message_remove_tag = &message_remove_tag_impl;
        msg_datetime = &msg_datetime_impl;
        return true;
    }
public:
    aot::tt::str_impl session_id_impl;
    aot::tt::str_impl user_id_impl;
    aot::tt::str_impl user_nickname_impl;
    aot::tt::str_impl message_impl;  
	aot::tt::str_impl message_remove_tag_impl;
    aot::tt::str_impl msg_datetime_impl;
};

class chat_log_op_impl : public aot::data::ichat_log_op
{
public:
    chat_log_op_impl(void);
public:
    virtual ~chat_log_op_impl(void);
public:    
    virtual bool insert(const ichat_log_info* record, int* new_id); 
    virtual bool del(int id); 
	virtual bool del_all();
	virtual bool del_all(const int chat_type, const char* session_id);
    virtual bool update(const ichat_log_info* record);

    virtual bool read(int id, isqlite3_table** out);
    virtual bool read(int id, ichat_log_info* out);
    virtual bool read(int id, ichat_log_info** out);

	virtual bool get_lastest_chat_log(int chat_type, const char* session_id, int count, 
		isqlite3_table** out, int record_id = 0);
    virtual int  get_records_total(int chat_type, const char* session_id);
    virtual bool get_page_records(int chat_type, const char* session_id, int count_per_page, 
		int page_no, isqlite3_table** out);

    virtual int  get_records_total_by_keyword(int chat_type, const char* session_id, const char* keyword);
    virtual bool get_page_records_by_keyword(int chat_type, const char* session_id, const char* keyword, 
		int count_per_page, int page_no, isqlite3_table** out);
	virtual bool get_records_by_date(int chat_type, const char* session_id, const char* min_date, 
		const char* max_date, int count_per_page, int* page, int* idx, isqlite3_table** out);
	virtual bool update_show_tag(int id, int status);
};

}} /* end namespace aot/data*/

#endif // __CHAT_LOG_OP__H__
